//
//  ZRTabBarController.m
//  SinaByOC
//
//  Created by 张锐 on 16/3/14.
//  Copyright © 2016年 zhangr. All rights reserved.
//

#import "ZRTabBarController.h"
#import "ZRNavigationController.h"
#import "ZRHomeViewController.h"
#import "ZRMessageViewController.h"
#import "ZRFindViewController.h"
#import "ZRSettingViewController.h"
#import "ZRTabBar.h"

@interface ZRTabBarController ()<ZRTabBarDelegate>

@end

@implementation ZRTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    //添加所有子控制器
    [self addChildViewControllers];
    
    
    //设置tabBar
    ZRTabBar * newTabBar = [[ZRTabBar alloc]init];
    
    newTabBar.tintColor = [UIColor orangeColor];
    
    newTabBar.composeDelegate = self;
    
    [self setValue:newTabBar forKey:@"tabBar"];
    
}
/**
 *  添加所有子控制器
 */
-(void)addChildViewControllers{
    
    [self addChildViewController:[[ZRHomeViewController alloc]init] andTitle:@"首页" andImageName:@"tabbar_home"];
    
    [self addChildViewController:[[ZRMessageViewController alloc]init] andTitle:@"消息" andImageName:@"tabbar_message_center"];
    
    [self addChildViewController:[[ZRFindViewController alloc]init] andTitle:@"发现" andImageName:@"tabbar_discover"];
    
    [self addChildViewController:[[ZRSettingViewController alloc]init] andTitle:@"设置" andImageName:@"tabbar_profile"];
}
/**
 *  添加子控制器
 *
 *  @param childController 子控制器
 *  @param title           子控制器标题
 *  @param imageName       子控制器图片
 */
-(void)addChildViewController:(UIViewController *)childController andTitle:(NSString *)title andImageName:(NSString *)imageName{
    
    childController.title = title;
    
    [childController.tabBarItem setImage:[UIImage imageNamed:imageName]];
    
    [childController.tabBarItem setSelectedImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@_highlighted",imageName]]];
    
    ZRNavigationController * navVc = [[ZRNavigationController alloc]initWithRootViewController:childController];
    
    if (![[NSUserDefaults standardUserDefaults] boolForKey:@"isLogin"]) {
        
        childController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"注册" style:UIBarButtonItemStylePlain target:navVc action:@selector(registerButtonClick)];
        
        childController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"登录" style:UIBarButtonItemStylePlain target:navVc action:@selector(loginButtonClick)];
    }
    
    
    [super addChildViewController:navVc];

}

/**
 *  compose按钮点击代理方法实现
 */
-(void)tabBarComposeButtonClickDelegate{
    
    NSLog(@"composeButton点击了一下");

}


@end
